//
//  KSRequest+Extension.swift
//  Supermarket
//
//  Created by liuxm on 2017/8/8.
//  Copyright © 2017年 kushao. All rights reserved.
//

import Foundation

// MARK: - 商家账户
extension KSRequest {
    
    /// 账号登录
    ///
    /// - Parameters:
    ///   - account: 用户登录名
    ///   - password: 密码
    ///   - delegate: delegate
    func requestLogin(account:String, password:String) {
        let parameters: [String: Any] = ["phone": account, "password": password]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSLogin)
    }
    
    /// 退出登录
    func requestLogOut() {
        self.excuteRequestWithParameters(parameters: [:], apiType: KSApiType.KSLogOut)
    }
    
    /// 检测账号是否被注册过
    ///
    /// - Parameter mobile: 	用户手机号
    func requestCheckRegister(mobile: String) {
        let parameters: [String: Any] = ["mobile": mobile]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSCheckRegister)
    }
    
    /// 获取推荐人登录名
    ///
    /// - Parameter inviteUser: 推荐人登录名
    func requestGetInvite(inviteUser: String) {
        let parameters: [String: Any] = ["invite_user": inviteUser]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSGetInvite)
    }
    
    /// 用户注册接口
    ///
    /// - Parameters:
    ///   - name     是     string     用户名
    ///   - password     是     string     密码
    ///   - password_confirmation     是     string     确认密码
    ///   - phone     是     string     电话
    ///   - email     否     string     邮箱
    func requestRegister(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSRegister)
    }
    
    /// 快捷登录 - 手机号验证码
    ///
    /// - Parameters:
    ///   - mobile: 手机号
    ///   - code: 验证码
    func requestLoginBysms(mobile:String, code:String) {
        let parameters: [String: Any] = ["mobile": mobile, "code": code]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSLoginBySms)
    }
    
    /// 发送验证短信
    ///
    /// - Parameters:
    ///   - mobile: 手机号
    ///   - tempId: 短信模板 1忘记密码 2注册验证码 3登录验证码
    func requestSendSMSLogin(mobile:String,tempId:String) {
        let parameters: [String: Any] = ["phone": mobile,"tempId": tempId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSSendCode)
    }
    
    /// 找回登录密码（未登录情况下）
    ///
    /// - Parameter parameters:
    ///   - mobile: 手机号
    ///   - code: 验证码
    ///   - new_password: 新密码
    ///   - confirm_password: 确认密码
    func requestForgetLoginPwd(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSForgetLoginPwd)
    }
    
    /// 账户设置(版本页)
    func requestAccountVersion() {
        self.excuteRequestWithParameters(parameters: [:], apiType: KSApiType.KSAccountVersion)
    }
    
    /// 内购单列表
    ///
    /// - Parameter parameters:
    ///   - storage_id             仓库id
    ///   - order_state            订单状态（多个以逗号分开）
    ///   - order_begin_time       下单开始时间
    ///   - order_end_time         下单结束时间
    ///   - page                   页码
    func requestGetOrderList(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIOSStorageOrderList)
    }
    
    /// 供货管理-订单详情
    ///
    /// - Parameter orderId:
    ///   - order_id              订单号
    func requestGetOrderDetail(orderId: String) {
        let parameters: [String: Any] = ["order_id": orderId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIOSStorageOrderDetail)
    }
    
    /// 内购单审核
    ///
    /// - Parameter parameters:
    ///   - order_ids                   array      订单id
    ///   - operate_state               int        审核结果：-1 审核拒绝、2 审核成功
    ///   - kuaidi_name                 string     快递名称
    ///   - kuaidi_code                 string     快递单号
    ///   - auditing_refuse_message     string     审核拒绝理由
    func requestOrderAuditing(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSOrderAuditing)
    }
    
    /// 出库 分配拣货操作
    ///
    /// - Parameter parameters:
    ///   - order_ids                   array     订单id
    ///   - picking_num                 array     拣货数量
    func requestOrderOutFPJH(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSOrderOutFPJH)
    }
    
    /// 出库 装车操作
    ///
    /// - Parameter orderIds:
    ///   - order_ids                   array     订单id
    func requestOrderOutZX(orderIds: [String]) {
        let parameters: [String: Any] = ["order_id": orderIds]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSOrderOutZX)
    }
    
    /// 添加配送箱
    ///
    /// - Parameter parameters:
    ///   - storage_id                  仓库id
    ///   - order_id                    订单id
    ///   - num                         配送箱数目
    func requestDeliveryBoxStore(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSDeliveryBoxStore)
    }
    
    /// 删除配送箱
    ///
    /// - Parameter parameters:
    ///   - storage_id                  仓库id
    ///   - order_id                    订单id
    ///   - delivery_box_id             配送箱id
    func requestDeliveryBoxDel(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSDeliveryBoxDel)
    }

    /// 差异单列表
    ///
    /// - Parameter parameters:
    ///   - page     否     int     页码 （默认1）
    ///   - order_number     否     string     差异单订单号 用于筛选
    ///   - storage_name     否     string     仓库名称 用于筛选
    ///   - merchant_name     否     string     商家名称 用于筛选
    ///   - start_date     否     string     订单创建的开始时间 用于筛选 例如 2017-09-01
    ///   - end_date
    func requestStorageOrderDiffList(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSStorageOrderDiffList)
    }
    
    /// 供应商管理
    ///
    /// - Parameter page: 页数
    func requestGetSellerStorage(page: String) {
        let parameters: [String: Any] = ["page": page]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSGetSellerStorage)
    }
    
    /// 差异单详情
    ///
    /// - Parameter orderNumber:  差异单订单号
    func requestStorageOrderDiffDetail(orderNumber: String) {
        let parameters: [String: Any] = ["order_number": orderNumber]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSStorageOrderDiffDetail)
    }
    
    /// 退款单列表
    ///
    /// - Parameter page: 页数
    func requestRefundList(parameters: [String: Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSRefundList)
    }
    
    /// 退款单详情
    ///
    /// - Parameter refundNumber: 退款单号 用于筛选
    func requestOrderRefundDetail(selectType: String,refundNumber: String) {
        let parameters: [String: Any] = ["refund_number": refundNumber,"select_type": selectType]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSOrderRefundDetail)
    }
    
    /// 上传图片
    ///
    /// - Parameters:
    ///   - type: 上传类型
    ///   - data: 图片数据
    func requestUpload(type: String,data: [String : Any]) {
        self.excutePhotoUploadWithParameters(type: type, datas: data, apiType: KSApiType.KSUpload)
    }
    
    /// 提交退款
    ///
    /// - Parameter parameters:
    func requestDoRefund(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSDoRefund)
    }
    
    /// 快递查询
    ///
    /// - Parameters:
    ///   - num: 物流单号
    ///   - kuaidiId: 快递id
    func requestLogisticDetail(num: String,kuaidiId: String) {
        let parameters: [String: Any] = ["num": num,"kuaidi_id": kuaidiId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSLogisticDetail)
    }
    
    /// 拣货单列表
    ///
    /// - Parameter parameters: 
    func requestIosStoragejhList(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageJhList)
    }
    
    /// 拣货详情
    ///
    /// - Parameter jhorderId: 订单id
    func requestIosStorageJhorderdetail(jhorderId: String) {
        let parameters: [String: Any] = ["jhorder_id": jhorderId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageJhorderdetail)
    }
    
    /// 分拣列表
    ///
    /// - Parameter parameters: 
    func requestIosStorageFjlist(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageFjlist)
    }
    
    /// 分拣详情
    ///
    /// - Parameter fjorderId:
    func requestIosStorageFjlistdetail(fjorderId: String) {
        let parameters: [String: Any] = ["jhorder_id": fjorderId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageFjListDetail)
    }
    
    /// 开始拣货页面
    ///
    /// - Parameter pickingId: 拣货id
    func requestIosStorageJhdetail(pickingId: String) {
        let parameters: [String: Any] = ["picking_id": pickingId]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageJhdetail)
    }
    
    /// 分配拣货操作
    ///
    /// - Parameters:
    ///   - orderIds: 订单id
    ///   - pickingNum: 拣货数量
    func requestIosOrderOutFPJH(orderIds: [String],pickingNum:[String]) {
        let parameters: [String : Any] = ["order_ids" : orderIds,"picking_num" : pickingNum]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosOrderOutFPJH)
    }
    
    /// 用户放弃认领权限
    ///
    /// - Parameter orderIds: 订单id
    func requestIosOrderDiscardGain(orderIds: [String]) {
        let parameters: [String : Any] = ["order_ids" : orderIds]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosOrderDiscardGain)
    }
    
    /// 添加配送箱
    ///
    /// - Parameter parameters: 
    func requestIosDeliveryBoxStore(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosDeliveryBoxStore)
    }
    
    /// 出库 分拣操作
    ///
    /// - Parameter parameters: 
    func requestIosOrderOutFJ(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosOrderOutFJ)
    }
    
    /// 出库 装车操作
    ///
    /// - Parameter orderIds: 
    func requestIosOrderOutZX(orderIds: [String]) {
        let parameters: [String: Any] = ["order_ids": orderIds]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosOrderOutZX)
    }
    
    /// 装车列表
    ///
    /// - Parameter parameters:
    func requestIosStorageZclist(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosStorageZclist)
    }
    
    /// 用户放弃认领权限
    ///
    /// - Parameter orderIds: 
    func requestOrderDiscardGain(orderIds: String) {
        let parameters: [String : Any] = ["order_ids" : orderIds]
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSOrderDiscardGain)
    }
    
    /// 内购单审核
    ///
    /// - Parameter parameters: 
    func requestIosOrderAuditing(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosOrderAuditing)
    }
    
    /// 快递列表
    func requestIosKuaidiList() {
        self.excuteRequestWithParameters(parameters: [:], apiType: KSApiType.KSIosKuaidiList)
    }
    
    
    /// 审核发货
    ///
    /// - Parameter parameters: 
    func requestIosAudiSend(parameters: [String : Any]) {
        self.excuteRequestWithParameters(parameters: parameters, apiType: KSApiType.KSIosAudiSend)
    }
}
